// 输入一个链表,反转链表后，输出新链表的表头

type Head = {
  [key: string]: any,
  next: Head | null
}

function gethead(head: Head) {
  if (!head) return null
  const stack = []
  let node: Head | null = head
  while (node) {
    stack.push(node.val)
    node = node.next
  }

  const newHead = {
    val: stack.pop(),
    next: null
  }

  node = newHead
  while (stack.length) {
    node.next = {
      val: stack.pop(),
      next: null
    }
    node = node?.next
  }

  return newHead

}


